package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.pojo.Member;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhouwei
 * @date 2020-01-10 19:13
 */
@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl implements ReportService{
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //获取当天时间
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周第一天
        String weekday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月第一天
        String monthday = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        Map<String,Object> map=new HashMap<>();
        map.put("reportDate",today);
        //本日新增会员
        Integer todayNewMember=memberDao.findMemberCountByDate(today);
        //本周新增会员，只要时间在周一之后，就是本周
        Integer thisweekMember=memberDao.findMemberCountAfterDate(weekday);
        //本月新增会员
        Integer thismonthMember = memberDao.findMemberCountAfterDate(monthday);
        //总会员数
        Integer totalCount = memberDao.findMemberTotalCount();
        //本日新增订单数
        Integer todayNewOrder = orderDao.findOrderCountByDate(today);
        //本周订单数
        Integer thisweekOrder = orderDao.findVisitsCountAfterDate(weekday);
        //本月订单数
        Integer thismonthOrder = orderDao.findOrderCountAfterDate(monthday);
        //本日到诊数
        Integer thisvisitsNumber = orderDao.findVisitsCountByDate(today);
        //本周到诊数
        Integer weekvisitsNumber = orderDao.findVisitsCountAfterDate(weekday);
        //本月到诊数
        Integer monthvisitsNumber = orderDao.findVisitsCountAfterDate(monthday);
        //热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalCount);
        map.put("thisWeekNewMember",thisweekMember);
        map.put("thisMonthNewMember",thismonthMember);
        map.put("todayOrderNumber",todayNewOrder);
        map.put("thisWeekOrderNumber",thisweekOrder);
        map.put("thisMonthOrderNumber",thismonthOrder);
        map.put("todayVisitsNumber",thisvisitsNumber);
        map.put("thisWeekVisitsNumber",weekvisitsNumber);
        map.put("thisMonthVisitsNumber",monthvisitsNumber);
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }
}
